/*delete space in string */
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
}
/*erase array element of index*/
Array.prototype.remove = function(index){
    var i = this.indexOf(index);
    if(i>=0) this.splice(i,1);else return false;
}
Array.prototype.append = function(obj){
    return this[this.length] = obj;
}
/*index what search value in array */
Array.prototype.valueOf = function(value){
    for(var i=0,l=this.length;i<l;i++){
        if(this[i] == value) return i;
    }
    return false;
}
/*get array element value what is max*/
Array.prototype.max = function(){
    var max = this[0];
    for(var i=1,l=this.length;i<l;i++){
        if(this[i]>max) max = this[1];
    }
    return max;
}
/*this defined innerText in firefox by textContent*/
if(isIe() == false){
    HTMLElement.prototype.__defineGetter__("innerText", 
    function(){
        var re = "";
        var nList = this.childNodes;
        for(var i=0; i<nList.length;i++){
            if(nList[i].nodeType==1)
                re += nList[i].tagName=="BR" ? '\n' : nList[i].textContent;
            else if(nList[i].nodeType==3)
                re += nList[i].nodeValue;
        }
        return re;
    }
    ); 
    HTMLElement.prototype.__defineSetter__("innerText", 
    function(sText){
        this.textContent=sText;
    }
    );
}
/*the document.getElementById extend*/
function $(id)
{
    var obj = __element.get(id);
    if(obj && obj.nodeName)
    {
        if(obj.nodeType == 3) return "text";
        if(obj.$extended) return obj;
        __extend(obj,extend);
        obj.$extended = true; 
        return obj;
    }
}
/*add extend function to $*/
var __extend = function()
{
    var args = arguments;
    if(!args[1])args = [this,args[0]]; 
    for(var property in args[1]) args[0][property] = args[1][property];
    return args[0];
}
/*return document.getElementById prototype*/
var __element = {get:function(Id){return document.getElementById(Id);}};
/*this is $ extend function*/
var extend = {
    /*create sub node obj of the element obj*/
    cSub : function(type,id)
    {
        this.subid = id;
        var obj = document.createElement(type);
        obj.id = this.subid;
        this.appendChild(obj);
        return $(this.subid);
    },
    /*set attribute of the element obj*/
    sAtt : function(name,value)
    {
       this.setAttribute(name,value);  
    },
    /*erase the id of element obj of sub node*/
    reSub : function(id)
    {
        if(this.isSub(id))
        {
            this.removeChild(id);
            return true;
        }else{
            return false;
        }
    },
    /*the id of obj what is the sub node of the obj*/
    isSub : function(id)
    {
        if(Emt.isId(id))
        {
            if($(id).parentNode.id == this.id)
            {
                return true;
            }
        }
        return false;
    },
    pointer : function(){
        this.style.cursor = "pointer";
    },
    pushClass : function(name){
        __pushClass(this,name);
    },
    listClass : function(style){
        __listClass(this,style);
    },
    removeClass : function(name){
        var tmp = Function("return /"+name+"/;");
        this.className = this.className.replace(tmp(),'');
    }  
};
/*the value is obj*/
var Emt = {
    isObj : function (obj){
        if(isObj(obj)) return true; else  return false;
    },
    isId  : function(id){
        if(this.isObj($(id))) return true; else return false;
    }
}
var __call = function(func){
    if(defined(func))
    {
        return Function("var arg=arguments;i=arg.length;if(i==0) args = arg[0];else{for(var m=0;m<i;m++){if(m==0) args = arg[0]; else args += ','+arg[m];}} return "+func+"(args);");
    }else{
        return false;
    }
};
var isObj = Function("value","if(typeof(value)== 'object') return true; else return false;");
function defined(str)
{
    if(typeof(str) != "string") return isset(str);
    try {
        var tmp = Function("str","return typeof("+str+");");
        var exist = tmp(str);
    }catch(e){
        return false;
    }
    if(exist =="undefined") return false;else return true;
}
function isset(obj)
{
    if(typeof(obj) == undefined || obj == '') return false;else return true;
}
function isIe(){if(document.all) return true;else return false;}
function isFF(){if(BV().n == 'Firefox') return true;else return false;}
function BV(){return {"n":navigator.appName,"v":navigator.appVersion};}
function __E(e)
{
    if(document.all)
        return event.srcElement;
    else
        return arguments[0].target;
}
function __Listener(element, e, act)
{
    if(element.addEventListener)
    {
        element.addEventListener(e,act,false);
    }else if(element.attachEvent){
        element.attachEvent("on"+e,act);
    }else{
        var elementEvent = element[e];
        element[e] = function()
        {
            var callEvent = elementEvent.apply(this,arguments);
            var actEvent  = act.apply(this,arguments);
            return (callEvent == undefined) ? actEvent : (actEvent == undefined ? callEvent : ( actEvent && callEvent));
        }
    }
}
function getDate(str)
{
    var myDate = new Date();
    var h = myDate.getHours();
    var i = myDate.getMinutes();
    var s = myDate.getSeconds();
    return h+":"+i+":"+s;
    /*if(str.indexOf('y') >=0) str.replace(/y/, myDate.getFullYear());
    if(str.indexOf('m') >=0) str.replace(/m/,myDate.getMonth());
    if(str.indexOf('d') >=0) str.replace(/d/,myDate.getDate());
    if(str.indexOf('h') >=0) str.replace(/h/,myDate.getHours());
    if(str.indexOf('i') >=0) str.replace(/i/,myDate.getMinutes());
    if(str.indexOf('s') >=0) str.replace(/s/,myDate.getSeconds());
    return str;*/
}
